package com.zsrt.oa.ticket.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsrt.oa.ticket.service.TicketService;
import com.zsrt.oa.ticket.service.impl.TicketServiceImpl;
import com.zsrt.utils.DBUtils;

/**
 * 门票的控制层
 * @author 罗智壕-13424431416
 *
 * 2017年6月9日
 */
public class TicketController extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	/**
	 * 初始化门票的服务层
	 */
	private TicketService service = new TicketServiceImpl();
       
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) 
			throws ServletException, IOException {
		
		String method = request.getParameter("method");
		if(null != method && !"".equals(method.trim())){
			
			Map<String, Object> map = new HashMap<String,Object>();
			if("ticketAdd".equals(method)){
				String ticketName = request.getParameter("ticketName");
				String ticketPrice = request.getParameter("ticketPrice");
				
				//调用增加门票
				service.ticketAdd(ticketName, ticketPrice, map);
			}else if("ticketQuery".equals(method)){
				String start = request.getParameter("start");
				String end = request.getParameter("end");
				
				//调用查询全部门票
				service.ticketQuery(start, end, map);
			}else if("ticketDelete".equals(method)){
				String ticketId = request.getParameter("ticketId");
				
				service.ticketDelete(ticketId, map);
			}else if("ticketFindById".equals(method)){
				String ticketId = request.getParameter("ticketId");
				
				service.ticketFindById(ticketId, map);
			}else if("ticketUpdate".equals(method)){
				String ticketName = request.getParameter("ticketName");
				String ticketPrice = request.getParameter("ticketPrice");
				String ticketId = request.getParameter("ticketId");
				String ticketStatus = request.getParameter("ticketStatus");
				
				//门票修改
				service.ticketUpdate(ticketName, ticketId, ticketStatus, ticketPrice, map);
			}
			
			DBUtils.toJson(map, response);
		}
	}
}
